#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
void bubbleSort(int list[], int listLength) {
	while(listLength--) 	{
		bool swapped = false;

		for(int i = 0; i < listLength; i++) {
			if(list[i] > list[i + 1]){
				swap(list[i], list[i + 1]);
				swapped = true;
			}
		}

		if(swapped == false) break;
	}
}

void read_from_file(const char *filename, int a[], int length) {
    ifstream file(filename);

    for(int i=0; i < length; i++)
        file >> a[i];
}
int main() {
    #define LEN 5000
    int a[LEN];

    read_from_file("m1_sorted.txt", a, LEN);
    int t_start1 = clock();
    bubbleSort(a, LEN);
    int t_finish1 = clock();
    cout << "m1:" << " " << t_finish1 - t_start1 << endl;

    read_from_file("m2_reverse.txt", a, LEN);
    int t_start2 = clock();
    bubbleSort(a, LEN);
    int t_finish2 = clock();
    cout << "m2:" << " " << t_finish2 - t_start2 << endl;

    read_from_file("m3_shuffle.txt", a, LEN);
    int t_start3 = clock();
    bubbleSort(a, LEN);
    int t_finish3 = clock();
    cout << "m3:" << " " << t_finish3 - t_start3 << endl;
}
